<script setup>
import { ref, watch,defineEmits } from 'vue'
import { baseURL } from '../utils/env';
const props = defineProps({
    photoUrl: {
        default: [],
    },
    nowNumber: {
        default: 0,
        type: Number,
    },
    isView: {
        default: false,
    }
})


const photoUrl = ref(props.photoUrl) || [];
const emit = defineEmits(['viewSwitch'])
const changeNumber = (e) => {
    if (e === 1 && props.nowNumber >= props.photoUrl.length - 1) return;
    if (e === 0 && props.nowNumber <= 0) return;
   emit('viewSwitch', e)
}

</script>

<template>
    <Transition name="view">
        <div class="viewer" v-if="props.isView">
            <div class="bg">
                <div class="viewer-photo">
                    <img  :src="baseURL + photoUrl[props.nowNumber]" alt="photo" class="photo-img" :key="props.nowNumber" />
                </div>
                <div class="switch sw-left" @click="changeNumber(0)" v-show="props.nowNumber>0">
                    <span class="iconfont icon-xiangzuo"  ></span>
                </div>
                <div class="switch sw-right" @click="changeNumber(1)" v-show="props.nowNumber<photoUrl.length-1">
                    <span class="iconfont icon-xiangyou"  ></span>
                </div>
            </div>
        </div>
    </Transition>
</template>

<style lang="less" scoped>
.view {
    //入场动画
    &-enter {
        &-from {
            opacity: 0;
        }

        &-active {
            transition: @tr;
        }

        &-to {
            opacity: 1;
        }
    }

    //离场动画
    &-leave {
        &-from {
            opacity: 1;
        }

        &-active {
            transition: @tr;
        }

        &-to {
            opacity: 0;
        }
    }
}

@import "../assets/fonts/icon/iconfont.css";

.viewer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;

    .bg {
        position: absolute;
        top: 0;
        left: 0;
        background-color: rgba(255, 255, 255, 0.8);
        backdrop-filter: blur(10px);
        height: 100%;
        width: 100%;
    }

    .viewer-photo {
        position: absolute;
        box-sizing: border-box;
        padding: 82px 454px 32px 96px;
        width: 100%;
        height: 100%;
        overflow-y: auto;
        display: flex;
        justify-content: center;
        .photo-img {
            max-width: 100%;
            max-height: none;  // 不限制最大高度
            height: auto;  // 高度自适应
            object-fit: contain;  // 保持比例完整显示
        }
    }

    .switch {
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background-color: @gray-3;
        color: @gray-10;
        position: absolute;
        top: 0;
        bottom: 0;
        margin: auto;
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0.5;
        transition: @tr;
        cursor: pointer;

        .iconfont {
            font-size: 24px;
        }

        &:hover {
            opacity: 1;
        }
    }

    .sw-left {
        left: 20px;
    }

    .sw-right {
        right: 380px;
    }
}
</style>
